/*
 * Copyright 2008 Zoundry LLC, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.zoundry.gaedt.userinput;

import org.eclipse.swt.widgets.Display;


/**
 * This class is used by the user input service to actually prompt the
 * user for the input.
 */
public class ZGaeUserInputPrompter
{
    /** Title of the prompt dialog. */
    private String mTitle;
    /** Message of the prompt dialog. */
    private String mMessage;
    /** Flag indicating whether the input is password input. */
    private boolean mPassword;

    /** The input dialog used to ask the user for input. */
    private ZGaeUserInputDialog mInputDialog;

    /**
     * C'tor.
     *
     * @param aTitle
     * @param aMessage
     * @param aIsPassword
     */
    public ZGaeUserInputPrompter(String aTitle, String aMessage, boolean aPassword)
    {
        setTitle(aTitle);
        setMessage(aMessage);
        setPassword(aPassword);
    }

    /**
     * Prompts the user for input.
     */
    public String prompt()
    {
        Display.getDefault().syncExec(new Runnable()
        {
            public void run()
            {
                mInputDialog = new ZGaeUserInputDialog(getTitle(), getMessage(), isPassword());
                mInputDialog.open();
            }
        });
        return mInputDialog.getValue();
    }

    /**
     * @return the title
     */
    protected String getTitle()
    {
        return mTitle;
    }

    /**
     * @param aTitle the title to set
     */
    protected void setTitle(String aTitle)
    {
        mTitle = aTitle;
    }

    /**
     * @return the message
     */
    protected String getMessage()
    {
        return mMessage;
    }

    /**
     * @param aMessage the message to set
     */
    protected void setMessage(String aMessage)
    {
        mMessage = aMessage;
    }

    /**
     * @return the password
     */
    protected boolean isPassword()
    {
        return mPassword;
    }

    /**
     * @param aPassword the password to set
     */
    protected void setPassword(boolean aPassword)
    {
        mPassword = aPassword;
    }
}
